"""
threading.main_thread()
    返回主线程对象，类似 threading.current_thread()；只不过一个是返回当前线程对象，一个是返回主线程对象
"""
import threading,time

def run(n):
    semaphore.acquire()
    print('-'*30)
    print('Now Pid is : %s' % threading.current_thread().ident) #返回当前线程ID
    print('Main Pid is : %s ' % threading.main_thread().ident) #返回主线程ID
    print('Now Thread is : %s ....' % threading.current_thread().getName())# 获取当前线程名
    print('Main thread is :%s ....' % threading.main_thread().getName())
    semaphore.release()

if __name__ == "__main__":
    semaphore = threading.BoundedSemaphore(1) #使用信号量保证线程按顺序运行
    threading.main_thread().setName('Chengd---python')
    for i in range(3):
        thread_alive = threading.Thread(target=run,args=(i,))
        thread_alive.start()
        #time.sleep(2)
    thread_alive.join()